<?php

class Emms_Form_Loan_LoanProduct extends HTech_Form
{
    public function __construct() 
    {
        parent::__construct();       
        
        $this->setName('LoanProduct');
        
        $this->setAttrib('title', $this->translate("Loan product form"));
        $this->setDescription($this->translate("Edit loan product information"));
          
        $loanProductId = new Zend_Form_Element_Hidden('LoanProductId');
        
        $name = new Zend_Form_Element_Text('Name');
        $name->setLabel("Name")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addFilter('Alpha', array('allowwhitespace' => true))
            ->addValidator('StringLength',false,
                array(
                    'min'      => 2,
                    'max'      => 128,
                    'messages' => $this->translate("From %min% to %max% characters only")
                ));
                                
        $interestCalculation = new Zend_Form_Element_Select('InterestCalculation');
        $interestCalculation->setLabel("Interest calculation")                
            ->setAttrib('size','1')
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addMultiOptions(array('' => $this->translate("--- Select option")) + 
                    array('Declining' => $this->translate("Declining balance"), 'Flat' => $this->translate("Flat rate")));  
                                
        $paymentFrequency = new Zend_Form_Element_Select('PaymentFrequency');
        $paymentFrequency->setLabel("Payment frequency")                
            ->setAttrib('size','1')
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addMultiOptions(array('' => $this->translate("--- Select option")) + 
                    array(
                        'W' => $this->translate("Weekly"), 
                        'BW' => $this->translate("Bi-Weekly"),
                        'M' => $this->translate("Monthly"),
                        'Q' => $this->translate("Quarterly"),
                        'SA' => $this->translate("Semi-Annual"),
                        'A' => $this->translate("Annual")));  
                                
        $calendarType = new Zend_Form_Element_Select('CalendarType');
        $calendarType->setLabel("Calendar type")                
            ->setAttrib('size','1')
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addMultiOptions(array('' => $this->translate("--- Select option")) + 
                    array('360' => '360', '365' => '365'));  
                       
        $installments = new Zend_Form_Element_Text('Installments');
        $installments->setLabel("Installments")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addFilter('Digits')
            ->addValidator('Int', true, array(
                    'messages' => $this->translate("Only numeric values allowed")));
                                
        $annualPercentageRate = new Zend_Form_Element_Text('AnnualPercentageRate');
        $annualPercentageRate->setLabel("Annual pct. rate")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Std. annual pct. rate can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Std. annual pct. rate")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $annualPercentageRateMin = new Zend_Form_Element_Text('AnnualPercentageRateMin');
        $annualPercentageRateMin->setLabel("Min. annual pct. rate")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Min. annual pct. rate can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Min. annual pct. rate")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $annualPercentageRateMax = new Zend_Form_Element_Text('AnnualPercentageRateMax');
        $annualPercentageRateMax->setLabel("Max. annual pct. rate")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Max. annual pct. rate can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Max. annual pct. rate")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $loanInsurancePct = new Zend_Form_Element_Text('LoanInsurancePct');
        $loanInsurancePct->setLabel("Loan ins. pct.")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Std. loan ins. pct. can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Std. loan ins. pct.")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $loanInsurancePctMin = new Zend_Form_Element_Text('LoanInsurancePctMin');
        $loanInsurancePctMin->setLabel("Min. loan ins. pct.")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Min. loan ins. pct. can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Min. loan ins. pct.")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $loanInsurancePctMax = new Zend_Form_Element_Text('LoanInsurancePctMax');
        $loanInsurancePctMax->setLabel("Max. loan ins. pct.")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Max. loan ins. pct. can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Max. loan ins. pct.")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $healthInsurancePct = new Zend_Form_Element_Text('HealthInsurancePct');
        $healthInsurancePct->setLabel("Health ins. pct.")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Std. health ins. pct. can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Std. health ins. pct.")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $healthInsurancePctMin = new Zend_Form_Element_Text('HealthInsurancePctMin');
        $healthInsurancePctMin->setLabel("Min. health ins. pct.")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Min. health ins. pct. can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Min. health ins. pct.")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $healthInsurancePctMax = new Zend_Form_Element_Text('HealthInsurancePctMax');
        $healthInsurancePctMax->setLabel("Max. health ins. pct.")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Max. health ins. pct. can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Max. health ins. pct.")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $administrativeFeePct = new Zend_Form_Element_Text('AdministrativeFeePct');
        $administrativeFeePct->setLabel("Admin. fee pct.")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Std. admin. fee pct. can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Std. admin. fee pct.")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $administrativeFeePctMin = new Zend_Form_Element_Text('AdministrativeFeePctMin');
        $administrativeFeePctMin->setLabel("Min. admin. fee pct")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Min. admin. fee pct. can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Min admin. fee pct.")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $administrativeFeePctMax = new Zend_Form_Element_Text('AdministrativeFeePctMax');
        $administrativeFeePctMax->setLabel("Max. admin. fee pct.")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Max. admin. fee pct. can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Max. admin. fee pct.")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                      
        $principalGraceMargin = new Zend_Form_Element_Text('PrincipalGraceMargin');
        $principalGraceMargin->setLabel("Principal grace - days")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addFilter('Digits')
            ->addValidator('Int', true, array(
                    'messages' => $this->translate("Only numeric values allowed")));
                                
        $principalGraceRate = new Zend_Form_Element_Text('PrincipalGraceRate');
        $principalGraceRate->setLabel("Principal grace rate")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Std. principal grace rate can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Std. principal grace rate")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $principalGraceRateMin = new Zend_Form_Element_Text('PrincipalGraceRateMin');
        $principalGraceRateMin->setLabel("Min. principal grace rate")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Min. principal grace rate can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Min. principal grace rate")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $principalGraceRateMax = new Zend_Form_Element_Text('PrincipalGraceRateMax');
        $principalGraceRateMax->setLabel("Max. principal grace rate")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Max. principal grace rate can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Max. principal grace rate")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                      
        $delayGrace = new Zend_Form_Element_Text('DelayGrace');
        $delayGrace->setLabel("Delay grace - days")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Required field, can't be empty")))
            ->addFilter('Digits')
            ->addValidator('Int', true, array(
                    'messages' => $this->translate("Only numeric values allowed")));
                                
        $delayPenaltyRate = new Zend_Form_Element_Text('DelayPenaltyRate');
        $delayPenaltyRate->setLabel("Daily delay rate")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Std. daily delay rate can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Std. daily delay rate")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $delayPenaltyRateMin = new Zend_Form_Element_Text('DelayPenaltyRateMin');
        $delayPenaltyRateMin->setLabel("Min. daily delay rate")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Min. daily delay rate can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Min. daily delay rate")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $delayPenaltyRateMax = new Zend_Form_Element_Text('DelayPenaltyRateMax');
        $delayPenaltyRateMax->setLabel("Max. daily delay rate")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Max. daily delay rate can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Max. daily delay rate")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $delayPenaltyFixedCharge = new Zend_Form_Element_Text('DelayPenaltyFixedCharge');
        $delayPenaltyFixedCharge->setLabel("Delay fixed charge")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Std. delay fixed charge can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Std. delay fixed charge")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $delayPenaltyFixedChargeMin = new Zend_Form_Element_Text('DelayPenaltyFixedChargeMin');
        $delayPenaltyFixedChargeMin->setLabel("Min. delay fixed charge")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Min. delay fixed charge can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Min. delay fixed charge")))
            ->addDecorator(new HTech_Form_Decorator_Bare());
                                
        $delayPenaltyFixedChargeMax = new Zend_Form_Element_Text('DelayPenaltyFixedChargeMax');
        $delayPenaltyFixedChargeMax->setLabel("Max. delay fixed charge")
            ->setRequired(true)
            ->addValidator('NotEmpty', true, array('messages' => $this->translate("Max. delay fixed charge can't be empty")))
            ->addValidator('Regex', true, array(
                'pattern' => '(^\d+(\.\d{2})?$)',
                'messages' => $this->translate("Invalid Max. delay fixed charge")))
            ->addDecorator(new HTech_Form_Decorator_Bare());  
                                
        $description = new Zend_Form_Element_Textarea('Description');
        $description->setLabel("Description")
            ->addFilter('Alnum', array('allowwhitespace' => true))
            ->setAttrib('rows', 3); 
        
        $submit = new Zend_Form_Element_Submit('Submit');
        $submit->setLabel("Submit")
            ->addDecorator(new HTech_Form_Decorator_Button(array('type' => 'submit')));  
                
        $this->setDecorators(array(array('ViewScript', array('viewScript' => 'loan-product/_form_add.phtml'))));      
        
        $this->addElements(array($loanProductId, $name, $interestCalculation, 
            $calendarType, $paymentFrequency, $installments, 
            $annualPercentageRate, $annualPercentageRateMin, $annualPercentageRateMax, 
            $loanInsurancePct, $loanInsurancePctMin, $loanInsurancePctMax, 
            $healthInsurancePct, $healthInsurancePctMin, $healthInsurancePctMax,
            $administrativeFeePct, $administrativeFeePctMin, $administrativeFeePctMax,
            $principalGraceMargin, $principalGraceRate, $principalGraceRateMin, $principalGraceRateMax,
            $delayGrace, $delayPenaltyRate, $delayPenaltyRateMin, $delayPenaltyRateMax,
            $delayPenaltyFixedCharge, $delayPenaltyFixedChargeMin, $delayPenaltyFixedChargeMax,
            $description, $submit));
    }
}